package com.zyf.wjy.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.zyf.wjy.entity.Field;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 地块DAO
 */
@Repository
public class FieldDao extends BaseDao<Field> {
    
    @Override
    protected String getFileName() {
        return "fields.json";
    }
    
    @Override
    protected TypeReference<List<Field>> getTypeReference() {
        return new TypeReference<List<Field>>() {};
    }
    
    @Override
    protected Long getId(Field entity) {
        return entity.getId();
    }
    
    @Override
    protected void setId(Field entity, Long id) {
        entity.setId(id);
    }
    
    /**
     * 根据地块编号查询
     */
    public Field findByFieldCode(String fieldCode) {
        return findAll().stream()
            .filter(field -> fieldCode.equals(field.getFieldCode()))
            .findFirst()
            .orElse(null);
    }
    
    /**
     * 根据状态查询
     */
    public List<Field> findByStatus(Integer status) {
        return findAll().stream()
            .filter(field -> status.equals(field.getStatus()))
            .toList();
    }
}

